<?php


namespace app\common\service\lib;


class MyRedis
{
    //封装带有布隆过滤器的Redis 防止其缓存穿透
    private $redis;
    private static $_instance = null; //定义单例模式的变量

    /**
     * 防止clone多个实例
     */
    private function __clone()
    {

    }

    private function __construct()
    {
        $this->redis = new \Redis();
        $result = $this->redis->connect('127.0.0.1', 6379);
        if ($result === false) {
            throw new \Exception('redis connect error');
        }
    }

    public static function getInstance()
    {
        if (empty(self::$_instance)) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    public function set($key,$filterName)
    {
       $this->redis->rawCommand('bf.add', $filterName, $key);
    }


    public function exists($key,$filterName)
    {
       return $this->redis->rawCommand('bf.exists', $filterName,$key);
    }

}